package cn.xiaopengstack.domain.order.model.valobj;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.ibatis.annotations.DeleteProvider;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * @author jiangyangang
 */
@Getter
@AllArgsConstructor
public enum AliPayResultMappingPayOrderStatusEnum {
    success(Arrays.asList("TRADE_SUCCESS"), PayOrderStatusEnumVO.pay_success),
    fail(Arrays.asList("TRADE_FAIL"), PayOrderStatusEnumVO.pay_fail),
    pay_process(null, PayOrderStatusEnumVO.pay_process),
    ;
    private final List<String> aliPayStatus;

    private final PayOrderStatusEnumVO payOrderStatusEnumVO;

    public static AliPayResultMappingPayOrderStatusEnum mappingResult(String aliPayResult){
        Optional<AliPayResultMappingPayOrderStatusEnum> resultOption = Stream.of(AliPayResultMappingPayOrderStatusEnum.values())
                .filter(statusEnum -> statusEnum.getAliPayStatus().contains(aliPayResult)).findFirst();

        return resultOption.orElse(AliPayResultMappingPayOrderStatusEnum.pay_process);
    }
}
